package com.esteel.settlement.config.validator;

import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.groups.Default;

import org.hibernate.validator.HibernateValidator;

/**
 * 报文验证程序
 * @author zhangxiuzhi
 *
 */
public class PacketValidator {
	
	private static final Validator validator = Validation.byProvider( HibernateValidator.class )
	        .configure()
	        .failFast( true )
	        .buildValidatorFactory()
	        .getValidator();
	
	/**
	 * 验证报文文件是否正确
	 * @param packate
	 * @return
	 */
	public <T> ValidatorResult<T> validator(T packet){
		Set<ConstraintViolation<T>> set = validator.validate(packet, Default.class);
		ValidatorResult<T> vResult = new ValidatorResult<T>(set.size()==0,set);
		return vResult;

	}

}
